package com.example.langchain4j_springboot.Config;

import com.example.langchain4j_springboot.Service.Assistant;
import com.example.langchain4j_springboot.Tools.BookingTools;
import dev.langchain4j.agent.tool.ToolSpecification;
import dev.langchain4j.community.model.dashscope.QwenChatModel;
import dev.langchain4j.community.model.dashscope.QwenEmbeddingModel;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.rag.content.retriever.EmbeddingStoreContentRetriever;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.inmemory.InMemoryEmbeddingStore;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

@Configuration
public class QwenAgentExecutor {
    @Resource
    private QwenChatModel qwenChatModel;

    @Bean
    public QwenEmbeddingModel qwenEmbeddingModel() {
        return QwenEmbeddingModel.builder()
                .apiKey("sk-332cb811beb84827b1dc157089c3184a")
                .modelName("text-embedding-v4")
                .build();
    }
 /*   @Bean("qwenAgentExecutor")
    public QwenAgentExecutor qwenAgentExecutor() {
        ToolSpecification.
    }*/
 @Bean
 public EmbeddingStore<TextSegment> initStore() {
     return new InMemoryEmbeddingStore<>();
 }
    @Bean
    @Scope(SCOPE_PROTOTYPE)
    ChatMemory chatMemory() {
        return MessageWindowChatMemory.withMaxMessages(10);
    }
    @Bean
    public Assistant assistant(EmbeddingStore<TextSegment> embeddingStore) {
        return AiServices.builder(Assistant.class)
                .chatLanguageModel(qwenChatModel)
                .contentRetriever(EmbeddingStoreContentRetriever.from(embeddingStore))
                .tools(new BookingTools())
                .build();
    }
}
